package com.rpframework.website.device.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.rpframework.core.BaseService;
import com.rpframework.utils.NumberUtils;
import com.rpframework.utils.Pager;
import com.rpframework.website.device.dao.IEstateDao;
import com.rpframework.website.device.domain.Estate;
import com.rpframework.website.device.domain.User;
import com.rpframework.website.device.util.HConstants;

@Service
public class EstateService extends BaseService{
	public @Resource IEstateDao iDao;

	
	public Pager<Estate> getPager(Pager<Estate> pager) {
		long startTime = System.currentTimeMillis();
		List<Estate> list = iDao.doPager(this.packageMyBatisParam(pager));
		pager.setItemList(list);
		pager.setCostTime(System.currentTimeMillis() - startTime);
		return pager;
	}

	public boolean doSaveOrUpdate(Estate t) {
		if(NumberUtils.isValid(t.getId())){
			if(t.getUrlList()==null){
				Estate DBEntity = iDao.select(t.getId());
				t.setUrlList(DBEntity.getUrlList());
			}
			t.setModifyTime(System.currentTimeMillis()/1000);
			return iDao.update(t);
		}
		t.setCreateTime(System.currentTimeMillis()/1000);
		return insert(t);
	}

	public List<Estate> queryAll() {
		return iDao.queryAll();
	}

	/**
	 * 更改实体状态 正常或禁用
	 * */
	public boolean doUpdateState(Integer id) {
		if(NumberUtils.isValid(id)){
			Estate t = iDao.select(id);
			if(t.getState() == HConstants.EntityState.STATE_NORMAL){
				t.setState(HConstants.EntityState.STATE_DISABLE);
			}else{
				t.setState(HConstants.EntityState.STATE_NORMAL);
			}
			t.setModifyTime(System.currentTimeMillis()/1000);
			return iDao.update(t);
		}
		return false;
	}

	public List<Estate> getListByCityCode(String code) {
	
		return iDao.doApiListByCityCode(code);
	}

	public Estate selectOnlyOne(int parseInt) {
		// TODO Auto-generated method stub
		return null;
	}

	public Estate selectOnlyOne1(int parseInt) {
		// TODO Auto-generated method stub
		return null;
	}

	public Pager<Estate> getpager(Pager<Estate> pager) {
		// TODO Auto-generated method stub
		return null;
	}
}
